

package com.hazelcast.security;

import com.hazelcast.cluster.Address;

import javax.security.auth.callback.CallbackHandler;
import java.util.Properties;

/**
 * ICredentialsFactory is used to create {@link Credentials} objects to be used during node authentication before connection is
 * accepted by the master node.
 */
public interface ICredentialsFactory {

    /**
     * This method is (only) called if the factory instance is newly created from a class name provided in
     * {@link com.hazelcast.config.CredentialsFactoryConfig}.
     *
     * @param properties factory properties defined in configuration
     */
    default void init(Properties properties) {
    }

    /**
     * Configures {@link ICredentialsFactory}.
     *
     * @param callbackHandler callback handler which can provide access to system internals
     */
    void configure(CallbackHandler callbackHandler);

    /**
     * Creates new {@link Credentials} object.
     *
     * @return the new Credentials object
     */
    Credentials newCredentials();

    /**
     * Creates new {@link Credentials} object for given target {@link Address}.
     *
     * @param address Target {@link Address} (may be {@code null})
     */
    default Credentials newCredentials(Address address) {
        return newCredentials();
    }

    /**
     * Destroys {@link ICredentialsFactory}.
     */
    void destroy();
}
